# Maintainer: Caleb Maclennan <caleb@alerque.com>

pkgbase=lua-luaepnf
_rockname=${pkgbase#lua-}
pkgname=("$pkgbase" "lua51-$_rockname" "lua52-$_rockname" "lua53-$_rockname")
pkgver=0.3
pkgrel=8
_rockrel=2
pkgdesc='Extended PEG Notation Format (easy grammars for LPeg)'
arch=(any)
url="https://github.com/siffiejoe/$pkgbase"
license=(MIT)
_luadeps=(lpeg)
makedepends=(lua
             lua51
             lua52
             lua53
             luarocks)
checkdepends=("${_luadeps[@]/#/lua-}")
_archive="$pkgbase-$pkgver"
_rockspec="$_rockname-$pkgver-$_rockrel.rockspec"
source=("$url/archive/v$pkgver/$_archive.tar.gz"
        "https://luarocks.org/manifests/siffiejoe/$_rockspec")
sha256sums=('57c0ad1917e45c5677bfed0f6122da2baff98117aba05a5e987a0238600f85f9'
            '4aa148cb1df45d83332fa2b0c7609ecb56b214c2ff13f06b62d7551e82b4154f')

check() {
	cd "$_archive/tests"
	for t in *.lua; do lua $t; done
}

_package() {
	cd "$_archive"
	depends=("${pkgname%-*}" "${_luadeps[@]/#/${pkgname%-*}-}")
	provides=("${pkgname/-lua/-}=$pkgver")
	luarocks --lua-version="$1" --tree="$pkgdir/usr/" \
		make --deps-mode=none --no-manifest "../$_rockspec"
	sed -ne '/^License$/,$p' README.md |
		install -Dm0644 /dev/stdin "$pkgdir/usr/share/licenses/$pkgname/LICENSE.md"
}

package_lua-luaepnf() {
	_package 5.4
}

package_lua51-luaepnf() {
	_package 5.1
}

package_lua52-luaepnf() {
	_package 5.2
}

package_lua53-luaepnf() {
	_package 5.3
}
